/*
 * Copyright 2005-2007 Pulse Technologies. Tutti i diritti riservati.
 */

package org.obsidianrad.server.services.obj2db.hessian;

import java.io.Serializable;

import org.obsidianrad.utils.Utils;




/**
 * 
 * @author eliosh
 * @version $Rev: 4 $
 * @lastautorcommit $Author: eliosh $
 * @lastdatecommit $Date: 2009-10-31 12:37:28 +0100(sab, 31 ott 2009) $
 */
public class CriteriaHessian implements Serializable {

	private static final long serialVersionUID = 6842524758475372221L;

	private CriteriaHessianMap[] internalCriteriaMap;

	public CriteriaHessian(){
		internalCriteriaMap = new CriteriaHessianMap[1];
	}
	
	protected void addCriterion(String condition) {
		if (condition != null) {
			CriteriaHessianMap chm = new CriteriaHessianMap(condition);
			internalCriteriaMap[internalCriteriaMap.length-1] = chm;
			internalCriteriaMap = (CriteriaHessianMap[]) Utils.resizeArray(internalCriteriaMap, internalCriteriaMap.length);
		}
	}

	protected void addCriterion(String condition, Object value, String property) {
		if (value != null) {
			CriteriaHessianMap chm = new CriteriaHessianMap(condition, value, property);
			internalCriteriaMap[internalCriteriaMap.length-1] = chm;
			internalCriteriaMap = (CriteriaHessianMap[]) Utils.resizeArray(internalCriteriaMap, internalCriteriaMap.length);
		}
	}

	protected void addCriterion(String condition, Object[] values, String property) {
		if (values != null && values.length == 0) {
			CriteriaHessianMap chm = new CriteriaHessianMap(condition, values, property);
			internalCriteriaMap[internalCriteriaMap.length-1] = chm;
			internalCriteriaMap = (CriteriaHessianMap[]) Utils.resizeArray(internalCriteriaMap, internalCriteriaMap.length);
		}
	}

	protected void addCriterion(String condition, Object value1, Object value2, String property) {
		if (! (value1 == null || value2 == null) ){
			CriteriaHessianMap chm = new CriteriaHessianMap(condition, value1, value2, property);
			internalCriteriaMap[internalCriteriaMap.length-1] = chm;
			internalCriteriaMap = (CriteriaHessianMap[]) Utils.resizeArray(internalCriteriaMap, internalCriteriaMap.length);
		}
	}


	public void addLessOrEqualFilter(String field, Object value) {
		addCriterion(field + " <=", value, field);
	}

	public void addLessFilter(String field, Object value) {
		addCriterion(field + " <", value, field);
	}

	public void addGreaterFilter(String field, Object value) {
		addCriterion(field + " >", value, field);
	}

	public void addGreaterOrEqualFilter(String field, Object value) {
		addCriterion(field + " >=", value, field);
	}

	public void addEqualFilter(String field, Object value) {
		addCriterion(field + " =", value, field);
	}

	public void addNotEqualFilter(String field, Object value) {
		addCriterion(field + " <>", value, field);
	}

	public void addLikeFilter(String field, Object value) {
		addCriterion(field + " like", value, field);
	}
	
	public void addNotLikeFilter(String field, Object value) {
		addCriterion(field + " not like", value, field);
	}
	
	public void addBetweenFilter(String field, Object valueMin, Object valueMax) {
		addCriterion(field + " BETWEEN", valueMin, valueMax, field);
	}

	public void addNotBetweenFilter(String field, Object valueMin, Object valueMax) {
		addCriterion(field + " NOT BETWEEN", valueMin, valueMax, field);
	}

	public void addIsNull(String field) {
		addCriterion(field + " is null");
	}

	public void addIsNotNull(String field) {
		addCriterion(field + " is not null");
	}

	public void addInList(String field, Object[] values){
		addCriterion(field + " in", values, field);
	}
	
	public void addNotInList(String field, Object[] values){
		addCriterion(field + " not in", values, field);
	}

	public CriteriaHessianMap[] getCriteriaMap() {
		return internalCriteriaMap;
	}

	public void setCriteriaMap(CriteriaHessianMap[] internalCriteriaMap) {
		this.internalCriteriaMap = internalCriteriaMap;
	}

}
